var type;
var servicelist = {};

apiready = function(){
	type = api.pageParam.type;
	
	$api.text($api.byId('title'), type);
	
	getList(type);
};


function enterOrder(index){
    
	if(type == '送水上门'){
		openWin('lifeservice_waterorder', {'type':type, 'serviceObj':servicelist[index]});
	}else{
		openWin('lifeservice_order', {'type':type, 'serviceObj':servicelist[index]});
	}
}


function call(index){
	var tel = servicelist[index].mobile;
	api.call({type: 'tel_prompt',number: tel});
}


function getList(type){
	api.showProgress({
		title: '加载中...',
		modal: false
	});
	 
	
	$api.get(serviceUrl+'/app/community/services?order=desc&type='+type,function(ret){
	    servicelist = ret.data;
		showList(ret.data);
  	  
	},'json');
}


function showList(list){
	
	var aHtml = "";
	
	if(servicelist.length > 0){
		
		for(var i = 0; i < servicelist.length; i++){

			var sjtype = servicelist[i].sjtype;
			
			aHtml += '<div class="am-u-sm-12" style="border-bottom:1px solid #e5e5e5;padding:8px;">';
	
			 	aHtml += '<div class="am-u-sm-10" style="padding:0px;">';
					aHtml += '<div class="am-u-sm-12" style="padding:0px;color:#393939;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">';
						aHtml += servicelist[i].name;
					aHtml += '</div>';
					aHtml += '<div class="am-u-sm-12" style="padding:0px;color:#949494;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">';
						aHtml += '<i class="am-icon-star" style="color:#ff4e25;"></i>';
			  			aHtml += '<i class="am-icon-star" style="color:#ff4e25;"></i>';
			  			aHtml += '<i class="am-icon-star" style="color:#ff4e25;"></i>';
			  			aHtml += '<i class="am-icon-star" style="color:#ff4e25;"></i>';
			  			aHtml += '<i class="am-icon-star" style="color:#ff4e25;"></i>';
			   			aHtml += '&nbsp;合作商家';
					aHtml += '</div>';
					
					if(sjtype == '可预约'){
						aHtml += '<div class="am-u-sm-12" style="padding:0px;color:#949494;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">';
							aHtml += '<font color="#ffaa43">提供预约服务</font>';
						aHtml += '</div>';
					}else{
						aHtml += '<div class="am-u-sm-12" style="padding:0px;color:#949494;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">';
							aHtml += '<font color="#ffaa43">' + servicelist[i].mobile + '</font>';
						aHtml += '</div>';
					}
					
				aHtml += '</div>';
				
				if(sjtype == '可预约'){
					aHtml += '<div class="am-u-sm-2" style="vertical-align: middle;text-align: center;border-left: 1px solid #e5e5e5;" onclick="enterOrder('+i+')">';
						aHtml += '<i class="am-icon-hand-o-right am-icon-sm" style="line-height:80px;"></i>';
					aHtml += '</div>';
				}else{
					aHtml += '<div class="am-u-sm-2" style="vertical-align: middle;text-align: center;border-left: 1px solid #e5e5e5;" onclick="call('+i+')">';
						aHtml += '<i class="am-icon-phone am-icon-sm" style="line-height:80px;"></i>';
					aHtml += '</div>';
				}
		
			aHtml += '</div>';
		}
		
	}
	
	$api.html($api.byId('servicelist'), aHtml);

	api.hideProgress();
}








